package com.baizhi.controller;

import com.baizhi.common.PageDTO;
import com.baizhi.entity.Exam;
import com.baizhi.service.ExamService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("exam")
public class ExamController {
    private ExamService examService;
    @Autowired
    public void setExamService(ExamService examService) {
        this.examService = examService;
    }
    @RequestMapping("showExam")
    public String showExam(PageDTO pd, Map map){
        PageInfo<Exam> pageInfo = examService.selectExams(pd.getName(), pd.getPageNum(), pd.getPageSize());
        map.put("pageNum",pd.getPageNum());
        map.put("totalPage",pageInfo.getPages());
        map.put("list",pageInfo.getList());
        return "manager/drug/examDrugList";
    }
    @RequestMapping("addExam")
    public String addExam(Exam exam){
        examService.insertExam(exam);
        return "redirect:showExam";
    }
    @RequestMapping("getOneExam")
    public String getOneExam(Integer eid,Map map){
        Exam exam = examService.selectById(eid);
        map.put("exam",exam);
        return "manager/drug/examDrug";
    }
    @RequestMapping("updateExam")
    public String updateExam(Exam exam){
        examService.updateExam(exam);
        return "redirect:showExam";
    }
}
